<%@page import="cn.qidisoft.edu.hzjt.model.Student"%>
<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>

<style>

table label.error {
    margin-left: 5px;
    width: auto;
    display: inline;
    color: red;
}
</style>
	<style type="text/css">
        .grid{font:12px arial,helvetica,sans-serif;border:1px solid #cccccc}
        .grid td{font:100% arial,helvetica,sans-serif;height:24px;padding:5px}
        .grid{width:100%;border-collapse:collapse}.grid th{background:#eeeeee;height:27px;line-height:27px;border:1px solid #cccccc;padding-left:5px}
        .grid td{border:1px solid #cccccc;padding-left:5px;text-align: center;}
    </style>
</head>
<body>
	<!-- 星级支部考核 -->
    <form action="#" name="Form" id="Form" method="post">
    	<input type="hidden" name="khid" id="khid" autocomplete="off"  class="inputText" value="${data.khid}"/>
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="95%">
			<tr>
				<td class="table-header" colspan="4">星级支部考核</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%"><font style="color: red;">*</font>党支部:</td>
				<td class="table-contentTD" style="width: 30%">
					<select class="selectList" id="dzbid" disabled="disabled" style="width: 70%">
					  <option value ="">全部</option>
					  <c:forEach items="${dzbsel}" var="data">
						  <option value ="${data.zBID}">${data.dZBMC}</option>
					  </c:forEach>
					</select>
				</td>
			   	<td class="table-titleTD" style="width: 15%"><font style="color: red;">*</font>考核年度:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="number" name="khnd" id="khnd" autocomplete="off" style="width: 70%"  class="required inputText" value="${data.khnd}"/></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">支部党员先锋指数上半年总分:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="number" id="sbnzf" name="sbnzf" autocomplete="off" readonly="readonly" maxlength="100" class="inputText" value="${data.sbnzf}"/></td>
		
			   	<td class="table-titleTD" style="width: 15%">支部党员先锋指数下半年总分:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="number" name="xbnzf" id="xbnzf" autocomplete="off" readonly="readonly" class="inputText" value="${data.xbnzf}" /></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">支部党员先锋指数全年平均值:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="number" id="qnpjz" name="qnpjz" autocomplete="off" readonly="readonly" maxlength="100" class="inputText" value="${data.qnpjz}" /></td>
		
			   	<td class="table-titleTD" style="width: 15%">民主测评情况:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="text" name="mzcpqk" id="mzcpqk" autocomplete="off"  class="inputText" value="${data.mzcpqk}"/></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 15%">总支委员会考核情况:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="text" id="zzwyhkhqk" name="zzwyhkhqk" autocomplete="off" maxlength="100" class=" inputText" value="${data.zzwyhkhqk}"/></td>
			
				<td class="table-titleTD" style="width: 15%">其他考核情况:</td>
				<td class="table-contentTD" style="width: 30%">
				<input type="text" name="qtkhqk" id="qtkhqk" autocomplete="off" class="inputText" value="${data.qtkhqk}" /></td>
			</tr>
		    <tr>
				<td class="table-titleTD" style="width: 15%"><font style="color: red;">*</font>星级:</td>
				<td class="table-contentTD" colspan="3" style="width: auto;">
					<label><input name="stars1" type="radio" value="1" />增加星级 </label> 
					<label><input name="stars1" type="radio" value="0" checked />保持原有星级 </label> 
					<label><input name="stars1" type="radio" value="-1" />降低星级 </label>
					<input type="hidden" name="stars" id="stars" autocomplete="off" class="inputText" value="${data.stars}" />
				</td>
			</tr>
			
		</table>
	</form>
	
	<!-- 操作表格 -->
		<br />
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<c:if test="${_login_user_type==2}">
			<tr>
			    <td>
			    	<kl:permission permisstionList="${permisstionList}"
               currentUser="${_login_console_user}"
               currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_KHGL_XJZB\")%>" key="modify">
			    <input type="button" id="btnSave" class="inputButton"
					style="text-align: center;" value="修改" />
				</kl:permission>
				</td>
				<td><input type="button" id="Cancel" class="inputButton"
					style="text-align: center;" value="取消" /></td>
				<td><input type="button" id="returnBut" class="inputButton"
					value="返回" style="text-align: center;" /></td>
			</tr>
		  </c:if>	
		</table>
		
	<script>
		var html;
		var year;
		window.onload = function() {
		   var now = new Date();
		   year = now.getFullYear();
		   
			// 去掉相同的option
			$("#dzbid option").each(function() {
			   var getText = $(this).val();
			   if($("#dzbid option:contains("+getText+")").length > 1){
			   		$("#dzbid option:contains("+getText+"):gt(0)").remove();
			   }
			});
		}
		
		$(document).ready(function() {
			    var dzbidsel = "${data.dzbid}";
	            var dzbmcsel = '${dzb.dZBMC}';
	            console.log(dzbidsel+"$$"+dzbmcsel);
	            $("#dzbid").val(dzbidsel);
			
			$("#khnd").blur(function(){
				if($("#khnd").val()>2099 || $("#khnd").val()<2010){
					layer.alert("请输入值不在2010到2099之间");
					$("#khnd").val(year);
				}else{
					if($("#dzbid option:selected").val()!="" && $("#khnd").val() != ""){
						getScoreData();
					}
				}
			});
			//得到表单数据
			function saveData(){
				var radio = $('input:radio:checked').val();
				var stars = $("#stars").val();
				if(parseInt(stars)+parseInt(radio)>10){
					layer.alert("已经到达10颗星上限");
				}else{
					$("#stars").val(parseInt(stars)+parseInt(radio));
					var _form=$("#Form").validate();
					if(_form.form()){
						var dzbid = $("#dzbid option:selected").val();
						document.Form.action ="${basePath}/partyBranchStar/update?action=1&dzbid=" + dzbid;
						document.Form.submit();
					}
				}
			}
			
			//返回方法
			function backList(){
				window.location.href = "${basePath}/partyBranchStar/list";
			}
			
			function saveData2(){
				var radio = $('input:radio:checked').val();
				var stars = $("#stars").val();
				if(parseInt(stars)+parseInt(radio)>10){
					layer.alert("已经到达10颗星上限");
				}else{
					$("#stars").val(parseInt(stars)+parseInt(radio));
					var _form=$("#Form").validate();
					if(_form.form()){
						var dzbid = $("#dzbid option:selected").val();
						document.Form.action ="${basePath}/partyBranchStar/add?action=2&dzbid=" + dzbid;
						document.Form.submit();
					}
				}
			}
			
			//返回按钮
			$("#returnBut").click(function(){
				backList();
			});
			
			//保存按钮
			$('#btnSave').click(function(){
				saveData();
			});
			
			// 点击保存并新增按钮
			$("#btnSaveContinue").click(function(){
				saveData2();
			});
			
			//取消按钮
			$("#Cancel").click(function() {
					   window.location.href = "${basePath}/partyBranchStar/preadd";
		 		});
			
			$("#dzbid").change(function(){
				if($("#dzbid option:selected").val()==""){
					//清空数据
					$("#qnpjz").val('');
					$("#sbnzf").val('');
					$("#xbnzf").val('');
					$("#mzcpqk").val('');
					$("#zzwyhkhqk").val('');
					$("#qtkhqk").val('');
				}else if($.trim($("#khnd").val())!=null && $.trim($("#khnd").val())!=''){
					getScoreData();
				}
			});
			
			$("#khnd").blur(function(){
				if($("#khnd").val()>2099 || $("#khnd").val()<2010){
					layer.alert("请输入值不在2010到2099之间");
					$("#khnd").val(year);
				}else{
					if($("#dzbid option:selected").val()!="" && $("#khnd").val() != ""){
						getScoreData();
					}
				}
			});
			
			$("#dzbid").change(function(){
				if($("#dzbid option:selected").val()==""){
					//清空数据
					$("#qnpjz").val('');
					$("#sbnzf").val('');
					$("#xbnzf").val('');
					$("#mzcpqk").val('');
					$("#zzwyhkhqk").val('');
					$("#qtkhqk").val('');
				}else if($.trim($("#khnd").val())!=null && $.trim($("#khnd").val())!=''){
					getScoreData();
				}
			});
			
		});//$(document).ready end
		//获取分数
		function getScoreData(){
			$.ajax({
				type:"post",
				url:"${basePath}/partyBranchStar/selZbdyfs2",
				data:{"year":$("#khnd").val(),"dzbid":$("#dzbid option:selected").val()},
				success:function(data){
					if(data.isExist!=null && data.isExist==1){
						alert('数据已存在，请勿重复添加');
						//清空数据//清空数据
						$("#khnd").val(year);
						$("#qnpjz").val('');
						$("#sbnzf").val('');
						$("#xbnzf").val('');
						$("#mzcpqk").val('');
						$("#zzwyhkhqk").val('');
						$("#qtkhqk").val('');
					}else{
						$("#sbnzf").val(data.score1);
						$("#xbnzf").val(data.score2);
						$("#qnpjz").val(data.avgScore);
						$("#stars").val(data.stars);
						$("#mzcpqk").val('');
						$("#zzwyhkhqk").val('');
						$("#qtkhqk").val('');
					}
				}
			});
		}

		//点击弹出添加学生div
		function showdiv() {
			$('#div1').dialog('open');
		}
	</script>
</body>
</html>